// pages/afterSaleCente/afterSaleCente.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //获取手机高度
    this.setData({
      navH: app.globalData.navHeight,
      str: options.str
    })
    var str1 = that.data.str.split(",");
    var product = str1[0]
    var qrId = str1[1]
    that.setData({
      productId:product
    })
    wx.request({
      url: app.globalData.url + 'getProductDetailByProductId',
      method: 'GET',
      data: {
        productId: product,
        qrId: qrId
      },
      success: function (res) {
        that.setData({
          product: res.data.data,
          detail: res.data.data.detail
        });
      },
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  navBack: function () {
    wx.navigateBack({
      delta:2
    })
  },

  gorecipeDetail:function(e){
    var that = this;
    var index = e.currentTarget.dataset.index;
    var json = that.data.cook[index].cookId;
   // json = JSON.stringify(json);
    wx.navigateTo({
      url: '/pages/recipeDetail/recipeDetail?cookId=' + that.data.cook[index].cookId,
    })
  },
  click:function(e){
    var that = this;
    var type = e.currentTarget.dataset.type;
    if (that.data.type == type) {
      return fasle;
    } else {
      that.setData({
        type: type
      })
      if (that.data.type == 1) {
        wx.request({
          url: app.globalData.url + 'getCookBookList',
          method: 'GET',
          data: {
            productId: that.data.productId
          },
          success: function (res) {
            that.setData({
              cook: res.data.data,
            });
          },
        });
      }
      if (that.data.type == 2) {
        wx.request({
          url: app.globalData.url + 'getCompanyInfo',
          method: 'GET',
          data: {
            companyId: that.data.product.product.companyId
          },
          success: function (res) {
            that.setData({
              company: res.data.data,
            });
          },
        });
      }
    }
  },
  toDetail:function(){
    var that = this;
    wx.navigateTo({
      url: '/pages/productDetail/productDetail?productid=' + that.data.product.product.productId,
    })
  },
})